<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="com.situ.web.entity.Banji"%>
<%@page import="java.util.List"%>
<%@page import="com.situ.web.entity.PageBean2"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
	<a href="<%=request.getContextPath() %>/banji_insert.jsp" class="btn btn-success">添加</a><br>
    <form action="<%=request.getContextPath() %>/banji?method=selectById" method="post" >
    	<input type="text" name="id">
    	<input type="submit" value="根据id查询" >
    </form><br> 
    <form action="<%=request.getContextPath() %>/banji?method=search" method="post" >
    	<input type="text" name="searchName">
    	<input type="submit" value="模糊查询" >
    </form><br>
	<table class="table table-striped table-bordered table-hover table-condensed">
	<tr>
			<td>ID</td>
			<td>名字</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<%
			PageBean2 pageBean = (PageBean2)request.getAttribute("pageBean");
			List<Banji> list = pageBean.getList();
			for(Banji banji :list){
		%>		
				<tr>
					<td><%=banji.getId()%></td>
					<td><%=banji.getName()%></td>
					<td><a href="javascript:void(0)" onclick="deleteById(<%=banji.getId()%>)">删除</a></td>
					<td><a href="javascript:void(0)" onclick="selectById(<%=banji.getId()%>)">修改</a></td>
				</tr>	
		<%		
			}
		%>
		</table>
		<nav aria-label="Page navigation">
            <ul class="pagination">
            <%if(pageBean.getPageNo()==1){%>
             	 <li class="disabled">
                <a href="#" aria-label="Previous">
                  <span aria-hidden="true">&laquo;</span>
                </a>
              </li>
            <%} else{%>
              <li>
                <a href="<%=request.getContextPath() %>/banji?method=pageList&pageNo=<%=pageBean.getPageNo()-1 %>&pageSize=3" class="btn btn-success" aria-label="Previous">
                  <span aria-hidden="true">&laquo;</span>
                </a>
              </li>
              <%} %>
              	<% for(int i = 1;i <= pageBean.getPageSize();i++) {
              		if(i==pageBean.getPageNo()){ 
              		%>
                  		<li><a href="#" class="active"><%=i %></a></li>
                  	<% 	
              		}else{%>
              			<li><a href="<%=request.getContextPath() %>/banji?method=pageList&pageNo=<%=i %>&pageSize=3" class="btn btn-success"><%=i %></a></li>
              		<% 	
              		}
              		} 
              		%>
               <%if(pageBean.getPageNo()==pageBean.getTotalPage()){%>
             	 <li class="disabled">
                <a href="#" aria-label="Previous">
                  <span aria-hidden="true">&raquo;</span>
                </a>
              </li>
            <%} else{%>
              <li>
                <a href="<%=request.getContextPath() %>/banji?method=pageList&pageNo=<%=pageBean.getPageNo()+1 %>&pageSize=3" class="btn btn-success" aria-label="Previous">
                  <span aria-hidden="true">&raquo;</span>
                </a>
              </li>
              <%} %>
            </ul>
		</nav>
		
</body>
<script type="text/javascript">
		function deleteById(id){
			var isDel = confirm("您确定要删除吗？");
			if(isDel){
				location.href = "<%=request.getContextPath() %>/banji?method=deleteById&id="+id;
			}
		}
		
		function selectById(id){
			var isDel = confirm("您确定要修改吗？");
			if(isDel){
				location.href = "<%=request.getContextPath() %>/banji?method=selectById2&id="+id;
			}
		}
		
	</script>
</html>